<?php

/**
 * Created by Reliese Model.
 */

namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Http\Request;

/**
 * Class ExhibitorMessage
 *
 * @property int $id
 * @property string|null $title
 * @property string|null $contents
 * @property string|null $addres
 * @property string|null $matters_needing_attention
 * @property string|null $contacts
 * @property string|null $contact_phone
 * @property string|null $e_mail
 * @property int|null $status
 * @property int|null $certificates_exhibitor_information_number
 * @property string|null $exhibitor_time
 *
 * @package App\Models
 */
class ExhibitorMessage extends Model
{
	protected $table = 'exhibitor_message';
	public $timestamps = false;

	protected $casts = [
		'status' => 'int',
		'certificates_exhibitor_information_number' => 'int'
	];

	protected $fillable = [
		'title',
		'contents',
		'addres',
		'matters_needing_attention',
		'contacts',
		'contact_phone',
		'e_mail',
		'status',
		'certificates_exhibitor_information_number',
		'exhibitor_time'
	];
    public function setContentsAttribute($contents)
    {
        $contents= request()->get('contents');
        dd($contents);
        if (is_array($contents)) {
            $this->attributes['contents'] = json_encode($contents);
        } else {
            $contents = explode(',', $contents);
            $this->attributes['contents'] = json_encode($contents);
        }
    }

    public function getContentsAttribute($contents)
    {
        return json_decode($contents, true);
    }
}
